from aiogram import Bot, Dispatcher, types, F
from dotenv import load_dotenv
import os
import asyncio
import logging
# from models import get_users, init, get_user, create_user
from aiogram.filters import CommandStart, Command
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove, Message, ContentType
from icecream import ic

import httpx
import http_rest
import insp_bot
# from app.keyboards import main_kb, inspection_k
# from utilites.utilits_bot import coincidence
# import bot_logic
import start_bot
import stat_bot
import end_work
from utilites.my_exp import queue

bot_token = os.getenv('TOKEN')
load_dotenv()
dp = Dispatcher()
ic.disable()
timeout = httpx.Timeout(10)
client = httpx.AsyncClient(timeout=timeout)


async def update_jurnal():
    while True:
        await bot.send_message(453994951, 'Сработало обновление журнала')
        await start_bot.process_bac(update_jur=True)
        await asyncio.sleep(10)


#bot_token = os.getenv('TOKEN')
#bot = Bot(token=bot_token, parse_mode='HTML')

clients = None

async def main():
    #bot_token = os.getenv('TOKEN')
    bot = Bot(token=bot_token, parse_mode='HTML')
    queue.start_worker(num_workers=2)
    logging.basicConfig(level=logging.INFO)
    #dp = Dispatcher()
    dp.include_router(start_bot.router)
    dp.include_router(stat_bot.router)
    dp.include_router(insp_bot.router)

    await bot.send_message(453994951, 'Бот запущен', reply_markup=types.ReplyKeyboardRemove())
    await bot.delete_webhook(drop_pending_updates=True)
    await dp.start_polling(bot)
    await asyncio.sleep(5)
    await queue.stop_workers()


if __name__ == '__main__':
    asyncio.run(main())
